package com.bw.wxy.factroy.interceptor;

import android.util.Log;

import com.blankj.utilcode.util.LogUtils;
import com.bw.wxy.common.SpUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class TokenInterceptor implements Interceptor {
    private static final String TAG = "TokenInterceptor";
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request(); //获取原有的请求
        Log.i(TAG, "request: "+request);
        Request.Builder builder = new Request.Builder();
        builder.url(request.url());
        builder.headers(request.headers());
        Log.i(TAG, "request.headers(): "+request.headers());
        builder.addHeader("token", SpUtils.readData("token"));
        builder.post(request.body());
        Log.i(TAG, "request.body(): "+request.body());
        LogUtils.e(request.body().toString());
        return chain.proceed(builder.build());
    }
}

